package demo.controller.student;

import demo.dao.FileDao;
import demo.dao.MarkDao;
import demo.dao.TaskDao;
import demo.dao.UserDao;
import demo.entity.LargeFile;
import demo.entity.Mark;
import demo.entity.Task;
import demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.UUID;

@Controller
@RequestMapping("/stu")
public class StuController {
    @Autowired(required = false)
    UserDao userDao;
    @Autowired(required = false)
    TaskDao taskDao;
    @Autowired(required = false)
    MarkDao markDao;
@GetMapping("/go2update")
    public String go2Update(Model model,HttpSession session){
    return "/stu/update";
}
    @PostMapping("/update")
    public String update(User user, Model model,HttpSession session){
        User user1 =(User) session.getAttribute("DL");//拿出用户
        user.setUid(user1.getUid());
        int update = userDao.update(user);//修改密码
        User user2 = userDao.findByUid(user1.getUid());
        session.setAttribute("DL",user2);//设置登录成功标志将用户放在session
        if (update>0) {
            model.addAttribute("update", "修改成功");
        }else  model.addAttribute("update", "修改失败");
        return "/stu/update";
    }
    @GetMapping("/findMyCourse")
    public String findMyCourse(Model model,HttpSession session){
        User user =(User) session.getAttribute("DL");//拿出用户
        List<Task> byClzno = taskDao.findByClzno(user.getClz().getClzno());
        model.addAttribute("course",byClzno);
        return "/stu/course";
    }
    @GetMapping("/findMyMark")
    public String findMyMark(Model model,HttpSession session){
        User user =(User) session.getAttribute("DL");//拿出用户
        List<Mark> byUid = markDao.findByUid(user.getUid());
        model.addAttribute("mark",byUid);
        return "/stu/mark";
    }
}
